from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-02-03 14:07:04.227067
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 03, Feb, 2021
Time: 14:07:09
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.7928
Nobs: 191.000 HQIC: -46.7045
Log likelihood: 2170.41 FPE: 2.80071e-21
AIC: -47.3253 Det(Omega_mle): 1.76931e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.461597 0.142171 3.247 0.001
L1.Burgenland 0.101250 0.073951 1.369 0.171
L1.Kärnten -0.221870 0.061155 -3.628 0.000
L1.Niederösterreich 0.126358 0.171201 0.738 0.460
L1.Oberösterreich 0.230841 0.149828 1.541 0.123
L1.Salzburg 0.199965 0.079448 2.517 0.012
L1.Steiermark 0.095164 0.106975 0.890 0.374
L1.Tirol 0.155286 0.071547 2.170 0.030
L1.Vorarlberg -0.003292 0.065376 -0.050 0.960
L1.Wien -0.131747 0.143661 -0.917 0.359
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.498102 0.175932 2.831 0.005
L1.Burgenland 0.020544 0.091512 0.224 0.822
L1.Kärnten 0.367634 0.075676 4.858 0.000
L1.Niederösterreich 0.115836 0.211855 0.547 0.585
L1.Oberösterreich -0.154599 0.185407 -0.834 0.404
L1.Salzburg 0.191252 0.098314 1.945 0.052
L1.Steiermark 0.240473 0.132378 1.817 0.069
L1.Tirol 0.138859 0.088537 1.568 0.117
L1.Vorarlberg 0.177227 0.080901 2.191 0.028
L1.Wien -0.583234 0.177775 -3.281 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.301196 0.063450 4.747 0.000
L1.Burgenland 0.106358 0.033004 3.223 0.001
L1.Kärnten -0.021023 0.027293 -0.770 0.441
L1.Niederösterreich 0.071275 0.076406 0.933 0.351
L1.Oberösterreich 0.286543 0.066868 4.285 0.000
L1.Salzburg 0.006058 0.035457 0.171 0.864
L1.Steiermark -0.020162 0.047743 -0.422 0.673
L1.Tirol 0.091345 0.031931 2.861 0.004
L1.Vorarlberg 0.110361 0.029177 3.782 0.000
L1.Wien 0.072962 0.064115 1.138 0.255
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.222189 0.071939 3.089 0.002
L1.Burgenland -0.015393 0.037419 -0.411 0.681
L1.Kärnten 0.024854 0.030944 0.803 0.422
L1.Niederösterreich 0.035002 0.086628 0.404 0.686
L1.Oberösterreich 0.385173 0.075813 5.081 0.000
L1.Salzburg 0.096288 0.040201 2.395 0.017
L1.Steiermark 0.185721 0.054130 3.431 0.001
L1.Tirol 0.039643 0.036203 1.095 0.274
L1.Vorarlberg 0.090503 0.033080 2.736 0.006
L1.Wien -0.066194 0.072692 -0.911 0.363
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.531183 0.143895 3.691 0.000
L1.Burgenland 0.066474 0.074848 0.888 0.374
L1.Kärnten 0.013642 0.061896 0.220 0.826
L1.Niederösterreich -0.015132 0.173277 -0.087 0.930
L1.Oberösterreich 0.149637 0.151645 0.987 0.324
L1.Salzburg 0.055187 0.080411 0.686 0.493
L1.Steiermark 0.117559 0.108272 1.086 0.278
L1.Tirol 0.206448 0.072415 2.851 0.004
L1.Vorarlberg 0.028037 0.066169 0.424 0.672
L1.Wien -0.141340 0.145403 -0.972 0.331
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.163017 0.101501 1.606 0.108
L1.Burgenland -0.018651 0.052797 -0.353 0.724
L1.Kärnten -0.012027 0.043660 -0.275 0.783
L1.Niederösterreich 0.129842 0.122227 1.062 0.288
L1.Oberösterreich 0.390725 0.106968 3.653 0.000
L1.Salzburg -0.024690 0.056721 -0.435 0.663
L1.Steiermark -0.029569 0.076374 -0.387 0.699
L1.Tirol 0.189341 0.051080 3.707 0.000
L1.Vorarlberg 0.037947 0.046675 0.813 0.416
L1.Wien 0.181495 0.102565 1.770 0.077
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.234073 0.130341 1.796 0.073
L1.Burgenland 0.067967 0.067798 1.002 0.316
L1.Kärnten -0.041797 0.056066 -0.745 0.456
L1.Niederösterreich -0.019706 0.156955 -0.126 0.900
L1.Oberösterreich -0.099123 0.137361 -0.722 0.471
L1.Salzburg 0.034104 0.072837 0.468 0.640
L1.Steiermark 0.391370 0.098074 3.991 0.000
L1.Tirol 0.492516 0.065594 7.509 0.000
L1.Vorarlberg 0.164753 0.059936 2.749 0.006
L1.Wien -0.222254 0.131707 -1.687 0.092
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.082712 0.157417 0.525 0.599
L1.Burgenland 0.033732 0.081881 0.412 0.680
L1.Kärnten -0.090266 0.067712 -1.333 0.183
L1.Niederösterreich 0.252505 0.189560 1.332 0.183
L1.Oberösterreich -0.000682 0.165894 -0.004 0.997
L1.Salzburg 0.231613 0.087967 2.633 0.008
L1.Steiermark 0.123730 0.118446 1.045 0.296
L1.Tirol 0.072715 0.079219 0.918 0.359
L1.Vorarlberg 0.042009 0.072387 0.580 0.562
L1.Wien 0.259060 0.159066 1.629 0.103
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.592119 0.083146 7.121 0.000
L1.Burgenland -0.025355 0.043249 -0.586 0.558
L1.Kärnten -0.002796 0.035765 -0.078 0.938
L1.Niederösterreich -0.041755 0.100124 -0.417 0.677
L1.Oberösterreich 0.286358 0.087624 3.268 0.001
L1.Salzburg 0.017344 0.046463 0.373 0.709
L1.Steiermark 0.017983 0.062562 0.287 0.774
L1.Tirol 0.079305 0.041843 1.895 0.058
L1.Vorarlberg 0.137799 0.038234 3.604 0.000
L1.Wien -0.056305 0.084017 -0.670 0.503
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.144546 0.029084 0.214642 0.262924 0.073811 0.087781 -0.056667 0.172202
Kärnten 0.144546 1.000000 0.015576 0.190302 0.162562 -0.114894 0.164586 0.024043 0.311572
Niederösterreich 0.029084 0.015576 1.000000 0.312937 0.086849 0.222815 0.145749 0.055357 0.370804
Oberösterreich 0.214642 0.190302 0.312937 1.000000 0.302092 0.305320 0.114140 0.081041 0.137700
Salzburg 0.262924 0.162562 0.086849 0.302092 1.000000 0.155158 0.055198 0.084394 -0.016047
Steiermark 0.073811 -0.114894 0.222815 0.305320 0.155158 1.000000 0.112946 0.093492 -0.086928
Tirol 0.087781 0.164586 0.145749 0.114140 0.055198 0.112946 1.000000 0.160520 0.155598
Vorarlberg -0.056667 0.024043 0.055357 0.081041 0.084394 0.093492 0.160520 1.000000 0.075055
Wien 0.172202 0.311572 0.370804 0.137700 -0.016047 -0.086928 0.155598 0.075055 1.000000